﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ent;
using DAL;
namespace BLL
{
    public class BusinessLogicLayer
    {
        public int RandomIndex(int size)
        {
            Random rd = new Random();
            int x = rd.Next(0, size - 1);

            return x;
        }
        public List<CauHoiThi> TronDanhSachCauHoi(List<CauHoiThi> Danhsach)
        {

            List<CauHoiThi> DanhsachMoi = new List<CauHoiThi>();
            List<CauHoiThi> DanhsachTemp = new List<CauHoiThi>();
            foreach (CauHoiThi i in Danhsach)
            {
                CauHoiThi ch = new CauHoiThi();
                ch.Flag = i.Flag;
                ch.HinhAnh = i.HinhAnh;
                ch.MaCauHoi = i.MaCauHoi;
                ch.NoiDung = i.NoiDung;
                ch.SoDapAnDung = i.SoDapAnDung;
                DanhsachTemp.Add(ch);
            }
            int count = DanhsachTemp.Count;
            while (count > 0)
            {
                int temp = RandomIndex(count);
                DanhsachMoi.Add(DanhsachTemp[temp]);
                DanhsachTemp.RemoveAt(temp);
                count--;
            }
            return DanhsachMoi;
        }
        public List<TraLoiThi> DanhsachDapAn_TheoListCauHoi(List<CauHoiThi> Dscauhoi)
        {
            DapAnDAL dadal = new DapAnDAL();
            List<TraLoiThi> DsDapAnMoi = new List<TraLoiThi>();
            List<TraLoiThi> DsDapAnChuaTron;
            List<TraLoiThi> DsDapAnTron;
            foreach (CauHoiThi ch in Dscauhoi)
            {
                DsDapAnChuaTron = new List<TraLoiThi>();
                DsDapAnChuaTron = dadal.DanhsachDapAn_Thi(ch.MaCauHoi);
                DsDapAnTron = new List<TraLoiThi>();
                DsDapAnTron = this.TronDanhSachDapAn(DsDapAnChuaTron);
                foreach (TraLoiThi da in DsDapAnTron)
                {
                    DsDapAnMoi.Add(da);
                }
            }
            return DsDapAnMoi;
        }
        public List<TraLoiThi> TronDanhSachDapAn(List<TraLoiThi> Danhsach)
        {
            List<TraLoiThi> DanhsachTemp = new List<TraLoiThi>();
            foreach (TraLoiThi i in Danhsach)
            {
                TraLoiThi temp = new TraLoiThi();
                temp.LoaiDA = i.LoaiDA;
                temp.NoiDung = i.NoiDung;
                temp.MaDapAn = i.MaDapAn;
                temp.HinhAnh = i.HinhAnh;
                temp.MaCauHoi = i.MaCauHoi;
                DanhsachTemp.Add(temp);
            }
            int count = DanhsachTemp.Count;
            List<TraLoiThi> DanhsachMoi = new List<TraLoiThi>();
            while (count > 0)
            {
                int temp = RandomIndex(count);
                DanhsachMoi.Add(DanhsachTemp[temp]);
                DanhsachTemp.RemoveAt(temp);
                count--;
            }
            return DanhsachMoi;
        }
    }
}
